package com.fsy.beanandsql.beantosql;

import com.fsy.beanandsql.beantosql.Bean.TestBean;
import com.fsy.beanandsql.beantosql.Bean.TestChildBean;
import com.fsy.beanandsql.beantosql.Bean.TestChildsBean;

import java.lang.reflect.Field;

/**
 * Created by shuangyufeng on 2017/5/5.
 */
public class TestGetClumns {

    public static void main(String[] args){
        //普通类获取类名称
        TestBean testBean = new TestBean();
        getClumns(testBean.getClass());

        System.out.println("<<<<<<<<===========分割线======================>>>>>>>");
        //继承类获取父类的名称
        TestChildBean testChildBean = new TestChildBean();
        getClumns(testChildBean.getClass());

        System.out.println("<<<<<<<<===========分割线======================>>>>>>>");
        //继承类获取父类的名称 再加一层试试
        TestChildsBean testChildsBean = new TestChildsBean();
        getClumns(testChildsBean.getClass());
    }

    private static void getClumns(Class<?> objClass){
        Field[] fieldArray = objClass.getDeclaredFields();
        for(Field field : fieldArray){
            System.out.println("field name : " + field.getName());
        }

        if(objClass.getSuperclass() != null){
            getClumns(objClass.getSuperclass());
        }
    }

}
